package com.xml_.jsoup_;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class Demo5 {
    public static void main(String[] args) throws IOException {
        String path = "src\\com\\xml_\\student.xml";
        // 1、获取Document对象
        Document document = Jsoup.parse(new File(path), "utf-8");

        // 2、获取所有的name标签
        Elements elements = document.select("name");
        System.out.println(elements);

        // 2、获取number值为a002的student标签下的age标签
        System.out.println("---------------------------------");
        // 2.1 获取number值为a002的student标签
        Elements elements1 = document.select("student[number='a002']");
        System.out.println(elements1);
        // 2.2 获取age子标签
        System.out.println("---------------------------------");
        Elements elements2 = document.select("student[number='a002'] > age");
        System.out.println(elements2);
    }
}
